﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.RouteOperationVMs
{
    public partial class RouteOperationListVM : BasePagedListVM<RouteOperation_View, RouteOperationSearcher>
    {
        
        protected override IEnumerable<IGridColumn<RouteOperation_View>> InitGridHeader()
        {
            return new List<GridColumn<RouteOperation_View>>{
                
                this.MakeGridHeader(x => x.RouteOperation_AddTime).SetTitle(@Localizer["Page.添加时间"].Value),
                this.MakeGridHeader(x => x.RouteOperation_EditTime).SetTitle(@Localizer["Page.编辑时间"].Value),
                this.MakeGridHeader(x => x.RouteOperation_LastOperationCode).SetTitle(@Localizer["Page.前工序编码"].Value),
                this.MakeGridHeader(x => x.RouteOperation_LineCode).SetTitle(@Localizer["Page.产线编码"].Value),
                this.MakeGridHeader(x => x.RouteOperation_NextNode).SetTitle(@Localizer["Page.下一个节点"].Value),
                this.MakeGridHeader(x => x.RouteOperation_NextOperationCode).SetTitle(@Localizer["Page.后工序编码"].Value),
                this.MakeGridHeader(x => x.RouteOperation_NextOperationId).SetTitle(@Localizer["Page.后工序ID"].Value),
                this.MakeGridHeader(x => x.RouteOperation_OperationCode).SetTitle(@Localizer["Page.工序编码"].Value),
                this.MakeGridHeader(x => x.RouteOperation_OperationId).SetTitle(@Localizer["Page.工序ID"].Value),
                this.MakeGridHeader(x => x.RouteOperation_OperationName).SetTitle(@Localizer["Page.工序名称"].Value),
                this.MakeGridHeader(x => x.RouteOperation_OrderCode).SetTitle(@Localizer["Page.工单编号"].Value),
                this.MakeGridHeader(x => x.RouteOperation_OrderId).SetTitle(@Localizer["Page.工单ID"].Value),
                this.MakeGridHeader(x => x.RouteOperation_ParentOperationCode).SetTitle(@Localizer["Page.父工序编码"].Value),
                this.MakeGridHeader(x => x.RouteOperation_ParentOperationId).SetTitle(@Localizer["Page.父工序ID"].Value),
                this.MakeGridHeader(x => x.RouteOperation_RouteName).SetTitle(@Localizer["Page.工艺路线名称"].Value),
                this.MakeGridHeader(x => x.RouteOperation_RouteNumber).SetTitle(@Localizer["Page.工艺路线编号"].Value),
                this.MakeGridHeader(x => x.RouteOperation_RouteVersion).SetTitle(@Localizer["Page.工艺路线版本"].Value),
                this.MakeGridHeader(x => x.RouteOperation_ScheduleNumber).SetTitle(@Localizer["Page.排程编号"].Value),
                this.MakeGridHeader(x => x.RouteOperation_Sort).SetTitle(@Localizer["Page.排序"].Value),
                this.MakeGridHeader(x => x.RouteOperation_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<RouteOperation_View> GetSearchQuery()
        {
            var query = DC.Set<RouteOperation>()
                
                .CheckBetween(Searcher.AddTime?.GetStartTime(), Searcher.AddTime?.GetEndTime(), x => x.AddTime, includeMax: false)
                .CheckBetween(Searcher.EditTime?.GetStartTime(), Searcher.EditTime?.GetEndTime(), x => x.EditTime, includeMax: false)
                .CheckContain(Searcher.LastOperationCode, x=>x.LastOperationCode)
                .CheckContain(Searcher.LineCode, x=>x.LineCode)
                .CheckContain(Searcher.NextNode, x=>x.NextNode)
                .CheckContain(Searcher.NextOperationCode, x=>x.NextOperationCode)
                .CheckContain(Searcher.NextOperationId, x=>x.NextOperationId)
                .CheckContain(Searcher.OperationCode, x=>x.OperationCode)
                .CheckContain(Searcher.OperationId, x=>x.OperationId)
                .CheckContain(Searcher.OperationName, x=>x.OperationName)
                .CheckContain(Searcher.OrderCode, x=>x.OrderCode)
                .CheckContain(Searcher.OrderId, x=>x.OrderId)
                .CheckContain(Searcher.ParentOperationCode, x=>x.ParentOperationCode)
                .CheckContain(Searcher.ParentOperationId, x=>x.ParentOperationId)
                .CheckContain(Searcher.RouteName, x=>x.RouteName)
                .CheckContain(Searcher.RouteNumber, x=>x.RouteNumber)
                .CheckContain(Searcher.RouteVersion, x=>x.RouteVersion)
                .CheckContain(Searcher.ScheduleNumber, x=>x.ScheduleNumber)
                .CheckContain(Searcher.Sort, x=>x.Sort)
                .Select(x => new RouteOperation_View
                {
				    ID = x.ID,
                    
                    RouteOperation_AddTime = x.AddTime,
                    RouteOperation_EditTime = x.EditTime,
                    RouteOperation_LastOperationCode = x.LastOperationCode,
                    RouteOperation_LineCode = x.LineCode,
                    RouteOperation_NextNode = x.NextNode,
                    RouteOperation_NextOperationCode = x.NextOperationCode,
                    RouteOperation_NextOperationId = x.NextOperationId,
                    RouteOperation_OperationCode = x.OperationCode,
                    RouteOperation_OperationId = x.OperationId,
                    RouteOperation_OperationName = x.OperationName,
                    RouteOperation_OrderCode = x.OrderCode,
                    RouteOperation_OrderId = x.OrderId,
                    RouteOperation_ParentOperationCode = x.ParentOperationCode,
                    RouteOperation_ParentOperationId = x.ParentOperationId,
                    RouteOperation_RouteName = x.RouteName,
                    RouteOperation_RouteNumber = x.RouteNumber,
                    RouteOperation_RouteVersion = x.RouteVersion,
                    RouteOperation_ScheduleNumber = x.ScheduleNumber,
                    RouteOperation_Sort = x.Sort,
                    RouteOperation_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class RouteOperation_View: RouteOperation
    {
        
        public DateTime? RouteOperation_AddTime { get; set; }
        public DateTime? RouteOperation_EditTime { get; set; }
        public string RouteOperation_LastOperationCode { get; set; }
        public string RouteOperation_LineCode { get; set; }
        public string RouteOperation_NextNode { get; set; }
        public string RouteOperation_NextOperationCode { get; set; }
        public string RouteOperation_NextOperationId { get; set; }
        public string RouteOperation_OperationCode { get; set; }
        public string RouteOperation_OperationId { get; set; }
        public string RouteOperation_OperationName { get; set; }
        public string RouteOperation_OrderCode { get; set; }
        public string RouteOperation_OrderId { get; set; }
        public string RouteOperation_ParentOperationCode { get; set; }
        public string RouteOperation_ParentOperationId { get; set; }
        public string RouteOperation_RouteName { get; set; }
        public string RouteOperation_RouteNumber { get; set; }
        public string RouteOperation_RouteVersion { get; set; }
        public string RouteOperation_ScheduleNumber { get; set; }
        public string RouteOperation_Sort { get; set; }
        public bool RouteOperation_IsValid { get; set; }

    }

}